﻿using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;

namespace NiuX.Dapper.Repositories;

/// <summary>
/// Dapper 仓储接口定义
/// </summary>
/// <typeparam name="TEntity"></typeparam>
public partial interface IDapperRepository<TEntity> where TEntity : class, new()
{
     Task<IEnumerable<TEntity>> QueryAsync(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null);

    /// <summary>
    /// <para>By default queries the table matching the class name</para>
    /// <para>-Table name can be overridden by adding an attribute on your class [Table("YourTableName")]</para>
    /// <para>By default filters on the Id column</para>
    /// <para>-Id column name can be overridden by adding an attribute on your primary key property [Key]</para>
    /// <para>Supports transaction and command timeout</para>
    /// <para>Returns a single entity by a single id from table T</para>
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="connection"></param>
    /// <param name="id"></param>
    /// <param name="transaction"></param>
    /// <param name="commandTimeout"></param>
    /// <returns>Returns a single entity by a single id from table T.</returns>
    Task<TEntity> GetAsync(object id, IDbTransaction transaction = null, int? commandTimeout = null);

    Task<TEntity> FirstAsync(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null);

    Task<TEntity> FirstAsAsync(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null);

    Task<TEntity> FirstOrDefaultAsync(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null);

}
